/*
 * CKeyboardBindKontrol.cpp
 *
 *  Created on: 06.10.2012
 *      Author: caffeine
 */

#include "CKeyboardBindKontrol.h"
#include <log/Log.h>

namespace irr {
namespace control {

CKeyboardBindKontrol::CKeyboardBindKontrol() {
}

CKeyboardBindKontrol::~CKeyboardBindKontrol() {
}

void CKeyboardBindKontrol::setBind(EKEY_CODE key,IKeyEvent*event){
	if (keymap[key].event){
		keymap[key].event->drop();
	}
	keymap[key].event=event;
	if (event)
		event->grab();
}

void CKeyboardBindKontrol::giveBind(EKEY_CODE key,IKeyEvent*event){
	setBind(key,event);
	if (event)
		event->drop();
	return;
}

bool CKeyboardBindKontrol::removeBind(EKEY_CODE key){
	if (!keymap[key].event)
		return false;
	keymap[key].event=0;
	return true;
}

bool CKeyboardBindKontrol::onKeyDown(EKEY_CODE key){
	if (keymap[key].down){
		return true;
	}
	if (!keymap[key].event){
		return false;
	}
	keymap[key].down=true;
	return keymap[key].event->onKeyDown(key);
}

bool CKeyboardBindKontrol::onKeyUp(EKEY_CODE key){
	if (!keymap[key].event){
		return false;
	}
	keymap[key].down=false;
	return keymap[key].event->onKeyUp(key);
}

} /* namespace control */
} /* namespace irr */
